<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools 1.3 参考文档 - Types/Array</title>
</head>

<body>
  <div id="docs" class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#Array">Array</a></h4>
      <div class="menu-item"><a href="#Array:Array-each">Array.each</a></div>
      <div class="menu-item"><a href="#Array:Array-clone">Array.clone</a></div>
      <div class="menu-item"><a href="#Array:Array-from">Array.from</a></div>
      <div class="menu-item"><a href="#Array:each">each</a></div>
      <div class="menu-item"><a href="#Array:invoke">invoke</a></div>
      <div class="menu-item"><a href="#Array:every">every</a></div>
      <div class="menu-item"><a href="#Array:filter">filter</a></div>
      <div class="menu-item"><a href="#Array:clean">clean</a></div>
      <div class="menu-item"><a href="#Array:indexOf">indexOf</a></div>
      <div class="menu-item"><a href="#Array:map">map</a></div>
      <div class="menu-item"><a href="#Array:some">some</a></div>
      <div class="menu-item"><a href="#Array:associate">associate</a></div>
      <div class="menu-item"><a href="#Array:link">link</a></div>
      <div class="menu-item"><a href="#Array:contains">contains</a></div>
      <div class="menu-item"><a href="#Array:append">append</a></div>
      <div class="menu-item"><a href="#Array:getLast">getLast</a></div>
      <div class="menu-item"><a href="#Array:getRandom">getRandom</a></div>
      <div class="menu-item"><a href="#Array:include">include</a></div>
      <div class="menu-item"><a href="#Array:combine">combine</a></div>
      <div class="menu-item"><a href="#Array:erase">erase</a></div>
      <div class="menu-item"><a href="#Array:empty">empty</a></div>
      <div class="menu-item"><a href="#Array:flatten">flatten</a></div>
      <div class="menu-item"><a href="#Array:pick">pick</a></div>
      <div class="menu-item"><a href="#Array:hexToRgb">hexToRgb</a></div>
      <div class="menu-item"><a href="#Array:rgbToHex">rgbToHex</a></div>
    </div>
    <div class="l-border r-border span-15 content">
      <h1 id="Array"><a href="#Array">类型: Array</a></h1>
      <p class="description">数组(Array)的功能增强</p>
      <h3>另参考:</h3>
      <ul>
        <li><a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">MDC Array</a></li>
      </ul>
      <h2 id="Array:Array-each"><a href="#Array:Array-each">函数: Array.each</a></h2>
      <p class="description">迭代数组(包括非常规数组,如由内建的getElementsByTagName方法返回的集合对象, arguments对象, 或Ojbect对象) </p>
      <h3>语法: </h3>
      <pre class="javascript">Array.<span class="me1">each</span><span class="br0">(</span>iterable, fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;</pre>
      <h3>参数: </h3>
      <ol>
        <li>iterable - (<em>array</em>) 被迭代的对象</li>
        <li>fn       - (<em>function</em>) 迭代过程中对每个迭代元素进行处理的函数</li>
        <li>bind     - (<em>object</em>, 可选) 迭代函数中‘this’所引用的对象. 详见 <a href="../../../docs/core/Types/Function.html#Function:bind">Function:bind</a>.</li>
      </ol>
      <h4>参数详解:  fn</h4>
      <h5>语法: </h5>
      <pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, object<span class="br0">)</span></pre>
      <h5>参数: </h5>
      <ol>
        <li>item   - (<em>mixed</em>) 当前迭代项</li>
        <li>index  - (<em>number</em>) 当前迭代项的索引. 如果迭代对象是一个Oject对象, 则是对象的属性名. </li>
        <li>object - (<em>mixed</em>) 迭代对象</li>
      </ol>
      <h3>示例: </h3>
      <pre class="javascript">Array.<span class="me1">each</span><span class="br0">(</span><span class="br0">[</span><span class="st0">'Sun'</span>, <span class="st0">'Mon'</span>, <span class="st0">'Tue'</span><span class="br0">]</span>, <span class="kw2">function</span><span class="br0">(</span>day, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw3">alert</span><span class="br0">(</span><span class="st0">'name:'</span> + day + <span class="st0">', index: '</span> + index<span class="br0">)</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">// 显示 'name: Sun, index: 0', 'name: Mon, index: 1', 等等. </span></pre>
      <h3>另参考:</h3>
      <ul>
        <li><a href="#Array:each">Array:each</a></li>
      </ul>
      <h3>提示: </h3>
      <p>这个函数功能与 MooTools 1.2 的 <em>$each</em> 相同. </p>
      <h2 id="Array:Array-clone"><a href="#Array:Array-clone">函数: Array.clone</a></h2>
      <p class="description">返回传入数组的一个克隆数组. </p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> clone = Array.<span class="me1">clone</span><span class="br0">(</span>myArray<span class="br0">)</span>;</pre>
      <h3>参数: </h3>
      <ol>
        <li>myArray  - (<em>array</em>) 要克隆的数组</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 传入数组的一个克隆数组. </li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> myArray = <span class="br0">[</span><span class="st0">'red'</span>, <span class="st0">'blue'</span>, <span class="st0">'green'</span><span class="br0">]</span>;
<span class="kw2">var</span> otherArray = Array.<span class="me1">clone</span><span class="br0">(</span>myArray<span class="br0">)</span>;
&nbsp;
<span class="kw2">var</span> myArray<span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span> = <span class="st0">'yellow'</span>;
&nbsp;
<span class="kw3">alert</span><span class="br0">(</span>myArray<span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span><span class="br0">)</span>;      <span class="co1">// 显示 'yellow'</span>
<span class="kw3">alert</span><span class="br0">(</span>otherArray<span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span><span class="br0">)</span>    <span class="co1">// 显示 'red'</span></pre>
      <h3>提示: </h3>
      <p>这个函数等同于 MooTools 1.2 的 <em>$unlink</em> . </p>
      <h2 id="Array:Array-from"><a href="#Array:Array-from">函数: Array.from</a></h2>
      <p class="description">如果传入的参数不是一个数组, 则将其包装成一个数组. </p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> splatted = Array.<span class="me1">from</span><span class="br0">(</span>obj<span class="br0">)</span>;</pre>
      <h3>参数: </h3>
      <ol>
        <li>obj - (<em>mixed</em>) 任意类型的变量</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 如果传入的参数是个数组, 那么返回该数组; 否则, 返回一个包含传入参数的数组. </li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript">Array.<span class="me1">from</span><span class="br0">(</span><span class="st0">'hello'</span><span class="br0">)</span>; <span class="co1">// 返回 ['hello'].</span>
Array.<span class="me1">from</span><span class="br0">(</span><span class="br0">[</span><span class="st0">'a'</span>, <span class="st0">'b'</span>, <span class="st0">'c'</span><span class="br0">]</span><span class="br0">)</span>; <span class="co1">// 返回 ['a', 'b', 'c'].</span></pre>
      <h3>提示: </h3>
      <p>这个函数等同于 MooTools 1.2 的 <em>$splat</em> . </p>
      <h2 id="Array:each"><a href="#Array:each">Array 方法:  each</a></h2>
      <p class="description">对数组进行迭代处理</p>
      <h3>语法: </h3>
      <pre class="javascript">myArray.<span class="me1">each</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;</pre>
      <h3>参数: </h3>
      <ol>
        <li>fn   - (<em>function</em>) 每次迭代中执行的函数. 当前迭代项及它的索引号将被作为参数传入该函数. </li>
        <li>bind - (<em>object</em>, 可选) 函数中this所引用的对象.  详见 <a href="../../../docs/core/Types/Function.html#Function:bind">Function:bind</a> . </li>
      </ol>
      <h4>参数详解: fn</h4>
      <h5>语法: </h5>
      <pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, array<span class="br0">)</span></pre>
      <h5>参数: </h5>
      <ol>
        <li>item   - (<em>mixed</em>) 当前迭代项</li>
        <li>index  - (<em>number</em>) 当前索引号</li>
        <li>array  - (<em>array</em>) 迭代的数组</li>
      </ol>
      <h3>示例: </h3>
      <pre class="javascript"><span class="co1">//显示 "0 = apple", "1 = banana", 等等……</span>
<span class="br0">[</span><span class="st0">'apple'</span>, <span class="st0">'banana'</span>, <span class="st0">'lemon'</span><span class="br0">]</span>.<span class="me1">each</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span><span class="kw1">item</span>, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw3">alert</span><span class="br0">(</span>index + <span class="st0">" = "</span> + <span class="kw1">item</span><span class="br0">)</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">//用于绑定的可选的第二个参数在这里没有使用</span></pre>
      <h3>另参考:</h3>
      <ul>
        <li><a href="#Array:Array-each">Array.each</a></li>
        <li><a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/forEach">MDC Array:forEach</a></li>
      </ul>
      <h3>提示: </h3>
      <ul>
        <li>这个方法只在没有原生 <a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/forEach">MDC Array:forEach</a> 方法支持的浏览器上生效(原文如此, 但实际上并非如此, 在存在 MDC Array 的浏览器上一样可以使用这个函数). </li>
      </ul>
      <h2 id="Array:invoke"><a href="#Array:invoke">Array 方法:  invoke</a></h2>
      <p class="description">遍历数组的各个成员, 执行其上定义的一个方法, 返回结果组成的数组. </p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> arr = myArray.<span class="me1">invoke</span><span class="br0">(</span>method<span class="br0">[</span>, arg, arg, arg ...<span class="br0">]</span><span class="br0">)</span></pre>
      <h3>参数: </h3>
      <ol>
        <li>method - (<em>string</em>) 要迭代数组成员的方法名称</li>
        <li>arg - (<em>mixed</em>) 该方法所需的参数</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 执行结果组成的数组</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> foo = <span class="br0">[</span><span class="nu0">4</span>, <span class="nu0">8</span>, <span class="nu0">15</span>, <span class="nu0">16</span>, <span class="nu0">23</span>, <span class="nu0">42</span><span class="br0">]</span>;
<span class="kw2">var</span> bar = foo.<span class="me1">invoke</span><span class="br0">(</span><span class="st0">'limit'</span>, <span class="nu0">10</span>, <span class="nu0">30</span><span class="br0">)</span>;  <span class="co1">//bar is now [10, 10, 15, 16, 23, 30]</span></pre>
      <h3>提示: </h3>
      <p>使用的方法应该是每个成员都拥有的. 如果某个成员的该方法不存在, 将会抛出异常. 举例: </p>
      <pre class="javascript"><span class="br0">[</span><span class="nu0">0</span>, <span class="kw2">false</span>, <span class="st0">'string'</span><span class="br0">]</span>.<span class="me1">invoke</span><span class="br0">(</span><span class="st0">'limit'</span>, <span class="nu0">0</span>, <span class="nu0">10</span><span class="br0">)</span>; <span class="co1">// 抛出一个异常!</span></pre>
      <h2 id="Array:every"><a href="#Array:every">Array 方法:  every</a></h2>
      <p class="description">如果数组中的每一项都通过给定函数的测试, 则返回 true . 这个方法只提供给没有原生 <a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/every">Array:every</a> 方法支持的浏览器. </p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> allPassed = myArray.<span class="me1">every</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;
</pre>
      <h3>参数: </h3>
      <ol>
        <li>fn   - (<em>function</em>) 用来测试每一个数组项的函数</li>
        <li>bind - (<em>object</em>, 可选) 函数中this所引用的对象. 详情请参看 <a href="../../../docs/core/Types/Function.html#Function:bind">Function:bind</a> . </li>
      </ol>
      <h4>参数详解:  fn</h4>
      <h5>语法: </h5>
      <pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, array<span class="br0">)</span></pre>
      <h5>参数: </h5>
      <ol>
        <li>item   - (<em>mixed</em>) 当前迭代项</li>
        <li>index  - (<em>number</em>) 当前索引号</li>
        <li>array  - (<em>array</em>) 迭代的数组</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>boolean</em>) 如果数组中的每一项都通过给定函数的测试, 则返回 true ;  否则, 返回 false . </li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> areAllBigEnough = <span class="br0">[</span><span class="nu0">10</span>, <span class="nu0">4</span>, <span class="nu0">25</span>, <span class="nu0">100</span><span class="br0">]</span>.<span class="me1">every</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span><span class="kw1">item</span>, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> <span class="kw1">item</span> &gt; <span class="nu0">20</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">// areAllBigEnough = false</span></pre>
      <h3>另参考:</h3>
      <ul>
        <li><a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/every">MDC Array:every</a></li>
      </ul>
      <h2 id="Array:filter"><a href="#Array:filter">Array 方法:  filter</a></h2>
      <p class="description">将所有在给定过滤函数中过滤通过的数组项创建一个新数组. 这个方法只提供给没有原生 <a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/filter">Array:filter</a> 方法支持的浏览器. </p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> filteredArray = myArray.<span class="me1">filter</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;</pre>
      <h3>参数: </h3>
      <ol>
        <li>fn   - (<em>function</em>) 用来测试每一个数组项的函数, 当前迭代项以及它的索引号将被作为参数传入该函数. </li>
        <li>bind - (<em>object</em>, 可选) 函数中this所引用的对象. 详情请参看 <a href="../../../docs/core/Types/Function.html#Function:bind">Function:bind</a> . </li>
      </ol>
      <h4>参数详解:  fn</h4>
      <h5>语法: </h5>
      <pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, array<span class="br0">)</span></pre>
      <h5>参数: </h5>
      <ol>
        <li>item   - (<em>mixed</em>) 当前迭代项</li>
        <li>index  - (<em>number</em>) 当前索引号</li>
        <li>array  - (<em>array</em>) 迭代的数组</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 过滤后的新数组</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> biggerThanTwenty = <span class="br0">[</span><span class="nu0">10</span>, <span class="nu0">3</span>, <span class="nu0">25</span>, <span class="nu0">100</span><span class="br0">]</span>.<span class="me1">filter</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span><span class="kw1">item</span>, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> <span class="kw1">item</span> &gt; <span class="nu0">20</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">// biggerThanTwenty = [25, 100]</span></pre>
      <h3>另参考:</h3>
      <ul>
        <li><a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/filter">MDC Array:filter</a></li>
      </ul>
      <h2 id="Array:clean"><a href="#Array:clean">Array 方法:  clean</a></h2>
      <p class="description">返回一个由原数组中计算值为true(即不是以下情况的值: null, undefined)的项</p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> cleanedArray = myArray.<span class="me1">clean</span><span class="br0">(</span><span class="br0">)</span>;
</pre>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 过滤后的新数组</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> myArray = <span class="br0">[</span><span class="kw2">null</span>, <span class="nu0">1</span>, <span class="nu0">0</span>, <span class="kw2">true</span>, <span class="kw2">false</span>, <span class="st0">'foo'</span>, undefined, <span class="st0">''</span><span class="br0">]</span>;
myArray.<span class="me1">clean</span><span class="br0">(</span><span class="br0">)</span> <span class="co1">// 返回 [1, 0, true, false, 'foo', '']</span>
</pre>
      <h2 id="Array:indexOf"><a href="#Array:indexOf">Array 方法:  indexOf</a></h2>
      <p class="description">返回数组中和给出参数值相等的项的索引号; 如果未找到相等的项, 则返回 -1 . 这个方法只提供给没有原生 <a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf">Array:indexOf</a> 方法支持的浏览器.       
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> index = myArray.<span class="me1">indexOf</span><span class="br0">(</span><span class="kw1">item</span><span class="br0">[</span>, from<span class="br0">]</span><span class="br0">)</span>;
</pre>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>number</em>) 数组中和给出参数值相等的项的索引号; 如果未找到相等的项, 则返回 -1 . </li>
      </ul>
      <h3>参数: </h3>
      <ol>
        <li>item - (<em>object</em>) 目标搜索项</li>
        <li>from - (<em>number</em>, 可选: 默认值为0) 在数组中搜索的起始索引号</li>
      </ol>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">[</span><span class="st0">'apple'</span>, <span class="st0">'lemon'</span>, <span class="st0">'banana'</span><span class="br0">]</span>.<span class="me1">indexOf</span><span class="br0">(</span><span class="st0">'lemon'</span><span class="br0">)</span>; <span class="co1">// 返回 1</span>
<span class="br0">[</span><span class="st0">'apple'</span>, <span class="st0">'lemon'</span><span class="br0">]</span>.<span class="me1">indexOf</span><span class="br0">(</span><span class="st0">'banana'</span><span class="br0">)</span>; <span class="co1">// 返回 -1</span></pre>
      <h3>另参考:</h3>
      <ul>
        <li><a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf">MDC Array:indexOf</a></li>
      </ul>
      <h2 id="Array:map"><a href="#Array:map">Array 方法:  map</a></h2>
      <p class="description">返回一个由经过给定函数处理返回的值所创建的新数组. 这个方法只提供给没有原生 <a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/map">Array:map</a> 方法支持的浏览器. </p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> mappedArray = myArray.<span class="me1">map</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;</pre>
      <h3>参数: </h3>
      <ol>
        <li>fn   - (<em>function</em>) 用来处理当前迭代项并返回新值的函数</li>
        <li>bind - (<em>object</em>, 可选) 函数中this所引用的对象. 详情请参看 <a href="../../../docs/core/Types/Function.html#Function:bind">Function:bind</a> . </li>
      </ol>
      <h4>参数详解: fn</h4>
      <h5>语法: </h5>
      <pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, array<span class="br0">)</span></pre>
      <h5>参数: </h5>
      <ol>
        <li>item   - (<em>mixed</em>) 当前迭代项</li>
        <li>index  - (<em>number</em>) 当前索引号</li>
        <li>array  - (<em>array</em>) 迭代的数组</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 处理后的新数组</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> timesTwo = <span class="br0">[</span><span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span><span class="br0">]</span>.<span class="me1">map</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span><span class="kw1">item</span>, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> <span class="kw1">item</span> * <span class="nu0">2</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">//timesTwo = [2, 4, 6];</span></pre>
      <h3>另参考:</h3>
      <ul>
        <li><a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/map">MDC Array:map</a></li>
      </ul>
      <h2 id="Array:some"><a href="#Array:some">Array 方法:  some</a></h2>
      <p class="description">如果数组中至少有一个项通过了给出的函数的测试, 则返回 true .  这个方法只提供给没有原生 <a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/some">Array:some</a> 方法支持的浏览器. </p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> somePassed = myArray.<span class="me1">some</span><span class="br0">(</span>fn<span class="br0">[</span>, bind<span class="br0">]</span><span class="br0">)</span>;</pre>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>boolean</em>) 如果数组中至少有一个项通过了给出的函数的测试, 则返回 true ;  否则返回 false . </li>
      </ul>
      <h3>参数: </h3>
      <ol>
        <li>fn   - (<em>function</em>) 用于测试数组项的函数. 当前数组中的迭代项以及它在数组中的索引号将被传入该函数中. </li>
        <li>bind - (<em>object</em>, 可选) 函数中this所引用的对象. 详情请参看 <a href="../../../docs/core/Types/Function.html#Function:bind">Function:bind</a>.</li>
      </ol>
      <h4>参数详解:  fn</h4>
      <h5>语法: </h5>
      <pre class="javascript">fn<span class="br0">(</span><span class="kw1">item</span>, index, array<span class="br0">)</span></pre>
      <h5>参数: </h5>
      <ol>
        <li>item   - (<em>mixed</em>) 当前迭代项</li>
        <li>index  - (<em>number</em>) 当前索引号</li>
        <li>array  - (<em>array</em>) 迭代的数组</li>
      </ol>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> isAnyBigEnough = <span class="br0">[</span><span class="nu0">10</span>, <span class="nu0">4</span>, <span class="nu0">25</span>, <span class="nu0">100</span><span class="br0">]</span>.<span class="me1">some</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span><span class="kw1">item</span>, index<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> <span class="kw1">item</span> &gt; <span class="nu0">20</span>;
<span class="br0">}</span><span class="br0">)</span>; <span class="co1">// isAnyBigEnough = true</span></pre>
      <h3>另参考:</h3>
      <ul>
        <li><a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/some">MDC Array:some</a></li>
      </ul>
      <h2 id="Array:associate"><a href="#Array:associate">Array 方法:  associate</a></h2>
      <p class="description">创建一个键值对对象, 该对象中的键由作为参数传入的一个数组决定, 值由主调数组决定. </p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> associated = myArray.<span class="me1">associate</span><span class="br0">(</span>obj<span class="br0">)</span>;
</pre>
      <h3>参数: </h3>
      <ol>
        <li>obj - (<em>array</em>) 作为键源的数组. </li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>object</em>) 合成后的键值对对象. </li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> animals = <span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span>, <span class="st0">'Cat'</span><span class="br0">]</span>;
<span class="kw2">var</span> sounds = <span class="br0">[</span><span class="st0">'Moo'</span>, <span class="st0">'Oink'</span>, <span class="st0">'Woof'</span>, <span class="st0">'Miao'</span><span class="br0">]</span>;
sounds.<span class="me1">associate</span><span class="br0">(</span>animals<span class="br0">)</span>;<span class="co1">// 返回 {'Cow': 'Moo', 'Pig': 'Oink', 'Dog': 'Woof', 'Cat': 'Miao'}</span></pre>
      <h2 id="Array:link"><a href="#Array:link">Array 方法:  link</a></h2>
      <p class="description">根据给出的 “键/测试函数”对 来创建一个新的键值对对象</p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> result = myArray.<span class="me1">link</span><span class="br0">(</span>object<span class="br0">)</span>;
</pre>
      <h3>参数: </h3>
      <ol>
        <li>object - (<em>object</em>)  包含 “键/测试函数” 的对象</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>object</em>) 新创建的键值对对象</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> el = document.<span class="me1">createElement</span><span class="br0">(</span><span class="st0">'div'</span><span class="br0">)</span>;
<span class="kw2">var</span> arr2 = <span class="br0">[</span><span class="nu0">100</span>, <span class="st0">'Hello'</span>, <span class="br0">{</span>foo: <span class="st0">'bar'</span><span class="br0">}</span>, el, <span class="kw2">false</span><span class="br0">]</span>;
arr2.<span class="me1">link</span><span class="br0">(</span><span class="br0">{</span>
    myNumber: Type.<span class="me1">isNumber</span>,
    myElement: Type.<span class="me1">isElement</span>,
    myObject: Type.<span class="me1">isObject</span>,
    myString: Type.<span class="me1">isString</span>,
    myBoolean: <span class="kw2">function</span><span class="br0">(</span>obj<span class="br0">)</span><span class="br0">{</span> <span class="kw1">return</span> obj != <span class="kw2">null</span>; <span class="br0">}</span>
<span class="br0">}</span><span class="br0">)</span>;
<span class="co1">// 返回 {myNumber: 100, myElement: el, myObject: {foo: 'bar'}, myString: 'Hello', myBoolean: false}</span>
<span class="co1">// 备注说明: 当前键的取值搜索范围是前一个键的测试挑选剩余后的数组项(而不是整个数组项)</span></pre>
      <h2 id="Array:contains"><a href="#Array:contains">Array 方法:  contains</a></h2>
      <p class="description">测试指定项是否在数组中存在</p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> inArray = myArray.<span class="me1">contains</span><span class="br0">(</span><span class="kw1">item</span><span class="br0">[</span>, from<span class="br0">]</span><span class="br0">)</span>;
</pre>
      <h3>参数: </h3>
      <ol>
        <li>item - (<em>object</em>) 要进行测试的项</li>
        <li>from - (<em>number</em>, 可选: 默认值为0) 在数组中开始搜索的起始位索引</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>boolean</em>) 如果数组包含给出的项, 则返回 true ; 否则返回 false . </li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">[</span><span class="st0">'a'</span>, <span class="st0">'b'</span>, <span class="st0">'c'</span><span class="br0">]</span>.<span class="me1">contains</span><span class="br0">(</span><span class="st0">'a'</span><span class="br0">)</span>; <span class="co1">// 返回 true</span>
<span class="br0">[</span><span class="st0">'a'</span>, <span class="st0">'b'</span>, <span class="st0">'c'</span><span class="br0">]</span>.<span class="me1">contains</span><span class="br0">(</span><span class="st0">'d'</span><span class="br0">)</span>; <span class="co1">// 返回 false</span></pre>
      <h3>另参考:</h3>
      <ul>
        <li><a target="_blank" href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf">MDC Array:indexOf</a></li>
      </ul>
      <h2 id="Array:append"><a href="#Array:append">Array 方法:  append</a></h2>
      <p class="description">将传入的数组追加到当前数组的末尾. </p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> myArray = myArray.<span class="me1">append</span><span class="br0">(</span>otherArray<span class="br0">)</span>;
</pre>
      <h3>参数: </h3>
      <ol>
        <li>otherArray - (<em>array</em>) 纳入源数组</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 纳入新项后的主调数组</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> myOtherArray = <span class="br0">[</span><span class="st0">'green'</span>, <span class="st0">'yellow'</span><span class="br0">]</span>;
<span class="br0">[</span><span class="st0">'red'</span>, <span class="st0">'blue'</span><span class="br0">]</span>.<span class="me1">append</span><span class="br0">(</span>myOtherArray<span class="br0">)</span>; <span class="co1">// 返回 ['red', 'blue', 'green', 'yellow'];</span>
myOtheArray; <span class="co1">// is now ['red', 'blue', 'green', 'yellow'];</span>
<span class="br0">[</span><span class="nu0">0</span>, <span class="nu0">1</span>, <span class="nu0">2</span><span class="br0">]</span>.<span class="me1">append</span><span class="br0">(</span><span class="br0">[</span><span class="nu0">3</span>, <span class="br0">[</span><span class="nu0">4</span><span class="br0">]</span><span class="br0">]</span><span class="br0">)</span>; <span class="co1">// [0, 1, 2, 3, [4]]</span>
</pre>
      <h3>提示: </h3>
      <p>这个函数功能与 MooTools 1.2 的 <em>Array:extend</em> 相同.  </p>
      <h2 id="Array:getLast"><a href="#Array:getLast">Array 方法:  getLast</a></h2>
      <p class="description">返回数组中的最后一项</p>
      <h3>语法: </h3>
      <pre class="javascript">myArray.<span class="me1">getLast</span><span class="br0">(</span><span class="br0">)</span>;</pre>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>mixed</em>) 数组中的最后一项</li>
        <li>(<em>null</em>) 如果是空数组, 则返回null</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span>, <span class="st0">'Cat'</span><span class="br0">]</span>.<span class="me1">getLast</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// 返回 'Cat'</span>
</pre>
      <h2 id="Array:getRandom"><a href="#Array:getRandom">Array 方法:  getRandom</a></h2>
      <p class="description">返回从数组中随机抽取的一项</p>
      <h3>语法: </h3>
      <pre class="javascript">myArray.<span class="me1">getRandom</span><span class="br0">(</span><span class="br0">)</span>;</pre>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>mixed</em>) 从数组中随机抽取的一项; 如果是空数组, 则返回null</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span>, <span class="st0">'Cat'</span><span class="br0">]</span>.<span class="me1">getRandom</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// 返回 one of the items</span>
</pre>
      <h2 id="Array:include"><a href="#Array:include">Array 方法:  include</a></h2>
      <p class="description">向数组中添加一项, 如果该项在数组中已经存在, 则不再添加.  (大小写与类型敏感)</p>
      <h3>语法: </h3>
      <pre class="javascript">myArray.<span class="me1">include</span><span class="br0">(</span><span class="kw1">item</span><span class="br0">)</span>;
</pre>
      <h3>参数: </h3>
      <ol>
        <li>item - (<em>object</em>) 目标添加项</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 添加元素后的主调数组</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span><span class="br0">]</span>.<span class="me1">include</span><span class="br0">(</span><span class="st0">'Cat'</span><span class="br0">)</span>; <span class="co1">// 返回 ['Cow', 'Pig', 'Dog', 'Cat']</span>
<span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span><span class="br0">]</span>.<span class="me1">include</span><span class="br0">(</span><span class="st0">'Dog'</span><span class="br0">)</span>; <span class="co1">// 返回 ['Cow', 'Pig', 'Dog']</span></pre>
      <h3>提示: </h3>
      <p>如果你想要将一个已经存在的元素压入数组, 使用原生的 javascript : </p>
      <pre class="javascript">myArray.<span class="me1">push</span><span class="br0">(</span><span class="kw1">item</span><span class="br0">)</span>;</pre>
      <h2 id="Array:combine"><a href="#Array:combine">Array 方法:  combine</a></h2>
      <p class="description">将主调数组和另一个数组进行组合(重复的项将不会加入, 大小写和类型敏感)</p>
      <h3>语法: </h3>
      <pre class="javascript">myArray.<span class="me1">combine</span><span class="br0">(</span>array<span class="br0">)</span>;</pre>
      <h3>参数: </h3>
      <ol>
        <li>array - (<em>array</em>) 将被组合的源数组</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 组合后的主调数组</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> animals = <span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span><span class="br0">]</span>;
animals.<span class="me1">combine</span><span class="br0">(</span><span class="br0">[</span><span class="st0">'Cat'</span>, <span class="st0">'Dog'</span><span class="br0">]</span><span class="br0">)</span>; <span class="co1">//animals = ['Cow', 'Pig', 'Dog', 'Cat'];</span>
</pre>
      <h2 id="Array:erase"><a href="#Array:erase">Array 方法:  erase</a></h2>
      <p class="description">删除数组中所有的指定项</p>
      <h3>语法: </h3>
      <pre class="javascript">myArray.<span class="me1">erase</span><span class="br0">(</span><span class="kw1">item</span><span class="br0">)</span>;
</pre>
      <h3>参数: </h3>
      <ol>
        <li>item - (<em>object</em>) 目标删除项</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 进行删除后的主调数组</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span>, <span class="st0">'Cat'</span>, <span class="st0">'Dog'</span><span class="br0">]</span>.<span class="me1">erase</span><span class="br0">(</span><span class="st0">'Dog'</span><span class="br0">)</span> <span class="co1">// 返回 ['Cow', 'Pig', 'Cat']</span>
<span class="br0">[</span><span class="st0">'Cow'</span>, <span class="st0">'Pig'</span>, <span class="st0">'Dog'</span><span class="br0">]</span>.<span class="me1">erase</span><span class="br0">(</span><span class="st0">'Cat'</span><span class="br0">)</span> <span class="co1">// 返回 ['Cow', 'Pig', 'Dog']</span></pre>
      <h2 id="Array:empty"><a href="#Array:empty">Array 方法:  empty</a></h2>
      <p class="description">清空数组</p>
      <h3>语法: </h3>
      <pre class="javascript">myArray.<span class="me1">empty</span><span class="br0">(</span><span class="br0">)</span>;</pre>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 清空后的主调数组</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> myArray = <span class="br0">[</span><span class="st0">'old'</span>, <span class="st0">'data'</span><span class="br0">]</span>;
myArray.<span class="me1">empty</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">//myArray 变成 []</span>
</pre>
      <h2 id="Array:flatten"><a href="#Array:flatten">Array 方法:  flatten</a></h2>
      <p class="description">将多维数组扁平化(即变为一维数组)</p>
      <h3>语法: </h3>
      <pre class="javascript">myArray.<span class="me1">flatten</span><span class="br0">(</span><span class="br0">)</span>;</pre>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>array</em>) 扁平化后的主调数组</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">var</span> myArray = <span class="br0">[</span><span class="nu0">1</span>,<span class="nu0">2</span>,<span class="nu0">3</span>,<span class="br0">[</span><span class="nu0">4</span>,<span class="nu0">5</span>, <span class="br0">[</span><span class="nu0">6</span>,<span class="nu0">7</span><span class="br0">]</span><span class="br0">]</span>, <span class="br0">[</span><span class="br0">[</span><span class="br0">[</span><span class="nu0">8</span><span class="br0">]</span><span class="br0">]</span><span class="br0">]</span><span class="br0">]</span>;
<span class="kw2">var</span> newArray = myArray.<span class="me1">flatten</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">//newArray 变成 [1,2,3,4,5,6,7,8]</span></pre>
      <h2 id="Array:pick"><a href="#Array:pick">Array 方法:  pick</a></h2>
      <p class="description">返回传入数组中第一个非未定义的项; 如果全部未定义, 则返回 null</p>
      <h3>语法: </h3>
      <pre class="javascript"><span class="kw2">var</span> picked = <span class="br0">[</span>var1, var2, var3<span class="br0">]</span>.<span class="me1">pick</span><span class="br0">(</span><span class="br0">)</span>;</pre>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>mixed</em>) 第一个非未定义的项</li>
        <li>(<em>null</em>) 如果都是 <code>null</code> 或 <code>undefined</code> , 则返回 <code>null</code> </li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="kw2">function</span> say<span class="br0">(</span>infoMessage, errorMessage<span class="br0">)</span><span class="br0">{</span>
    <span class="kw3">alert</span><span class="br0">(</span><span class="br0">[</span>errorMessage, infoMessage, <span class="st0">'There was no message supplied.'</span><span class="br0">]</span>.<span class="me1">pick</span><span class="br0">(</span><span class="br0">)</span><span class="br0">)</span>;
    <span class="co1">//或者 MooTools 1.2 的使用风格</span>
    Array.<span class="me1">pick</span><span class="br0">(</span><span class="br0">[</span>errorMessage, infoMessage, <span class="st0">'There was no message supplied.'</span><span class="br0">]</span><span class="br0">)</span>;
<span class="br0">}</span>
say<span class="br0">(</span><span class="br0">)</span>; <span class="co1">// 显示 'There was no message supplied.'</span>
say<span class="br0">(</span><span class="st0">'This is an info message.'</span><span class="br0">)</span>; <span class="co1">// 显示 'This is an info message.'</span>
say<span class="br0">(</span><span class="st0">'This message will be ignored.'</span>, <span class="st0">'This is the error message.'</span><span class="br0">)</span>; <span class="co1">// 显示 'This is the error message.'</span>
</pre>
      <h3>提示: </h3>
      <p>这个函数等同于 MooTools 1.2 的 <em>$pick</em> . </p>
      <h2 id="Array:hexToRgb"><a href="#Array:hexToRgb">Array 方法:  hexToRgb</a></h2>
      <p class="description">将十六进制的颜色代码转换成RGB格式的代码. 输入的RGB代码需要类似如下的16进制格式: ['FF', 'FF', 'FF']</p>
      <h3>语法: </h3>
      <pre class="javascript">myArray.<span class="me1">hexToRgb</span><span class="br0">(</span><span class="br0">[</span>array<span class="br0">]</span><span class="br0">)</span>;</pre>
      <h3>参数: </h3>
      <ol>
        <li>array - (<em>boolean</em>, 可选) 是否输出为数组. 如果为 true , 则输出的RGB格式的颜色将是数组格式 (如 [255, 51, 0])而不是原本的字符串形式(如 "rgb(255, 51, 0)")</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>string</em>) RGB格式的颜色代码字符串</li>
        <li>(<em>array</em>) 如果设置了输出格式为数组, 则返回数组格式的RGB颜色代码</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">[</span><span class="st0">'11'</span>, <span class="st0">'22'</span>, <span class="st0">'33'</span><span class="br0">]</span>.<span class="me1">hexToRgb</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// 返回 'rgb(17, 34, 51)'</span>
<span class="br0">[</span><span class="st0">'11'</span>, <span class="st0">'22'</span>, <span class="st0">'33'</span><span class="br0">]</span>.<span class="me1">hexToRgb</span><span class="br0">(</span><span class="kw2">true</span><span class="br0">)</span>; <span class="co1">// 返回 [17, 34, 51]</span></pre>
      <h3>另参考:</h3>
      <ul>
        <li><a href="../../../docs/core/Types/String.html#String:hexToRgb">String:hexToRgb</a></li>
      </ul>
      <h2 id="Array:rgbToHex"><a href="#Array:rgbToHex">Array 方法:  rgbToHex</a></h2>
      <p class="description">将RGB格式的颜色代码转换成十六进制的代码. 输入的RGB代码需要类似如下的其中一种格式: [255,255,255] 或 [255,255,255,1]</p>
      <h3>语法: </h3>
      <pre class="javascript">myArray.<span class="me1">rgbToHex</span><span class="br0">(</span><span class="br0">[</span>array<span class="br0">]</span><span class="br0">)</span>;
</pre>
      <h3>参数: </h3>
      <ol>
        <li>array - (<em>boolean</em>, 可选) 是否输出为数组. 如果为 true , 则输出的十六进制颜色将是数组格式(如: ['ff','33','00'] ), 而不是原本的字符串形式(如: "#ff3300" )</li>
      </ol>
      <h3>返回值: </h3>
      <ul>
        <li>(<em>string</em>) 字符串格式的十六进制颜色代码, 或者若主调数组是一个代表 rgba 的颜色代码(即除了R,G,B外,还有一个Alpha值), 且第四个值是 0 , 则返回 'transparent' (透明)</li>
        <li>(<em>array</em>) 如果设置了输出格式为数组, 则返回数组格式的十六进制颜色代码</li>
      </ul>
      <h3>示例: </h3>
      <pre class="javascript"><span class="br0">[</span><span class="nu0">17</span>, <span class="nu0">34</span>, <span class="nu0">51</span><span class="br0">]</span>.<span class="me1">rgbToHex</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// 返回 '#112233'</span>
<span class="br0">[</span><span class="nu0">17</span>, <span class="nu0">34</span>, <span class="nu0">51</span><span class="br0">]</span>.<span class="me1">rgbToHex</span><span class="br0">(</span><span class="kw2">true</span><span class="br0">)</span>; <span class="co1">// 返回 ['11', '22', '33']</span>
<span class="br0">[</span><span class="nu0">17</span>, <span class="nu0">34</span>, <span class="nu0">51</span>, <span class="nu0">0</span><span class="br0">]</span>.<span class="me1">rgbToHex</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// 返回 'transparent'</span>
</pre>
      <h3>另参考:</h3>
      <ul>
        <li><a href="../../../docs/core/Types/String.html#String:rgbToHex">String:rgbToHex</a></li>
      </ul>
    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
